<!--  -->
<template>
  <div class="app-container">
    <el-form :inline="true" size="small">
      <el-form-item label="模板编号">
        <el-input
          v-model="mId"
          placeholder="请输入分类编号"
          size="small"
        ></el-input>
      </el-form-item>
      <el-form-item label="模板名称">
        <el-input
          v-model="mName"
          placeholder="请输入分类名称"
          size="small"
        ></el-input>
      </el-form-item>

      <el-button icon="el-icon-search" type="primary" size="small" @click
        >搜索</el-button
      >
      <el-button icon="el-icon-refresh" size="small" @click>重置</el-button>
      <el-button icon="el-icon-edit" type="warning" size="small" @click="add"
        >新增</el-button
      >
      <el-button icon="el-icon-delete" type="danger" size="small" @click
        >删除</el-button
      >

      <el-button
        class="ref-btn"
        icon="el-icon-refresh"
        circle
        @click
      ></el-button>
    </el-form>
    <el-table :data="tableData" border stripe>
      <el-table-column
        type="selection"
        width="60"
        align="center"
      ></el-table-column>

      <template v-for="(i, index) in columns">
        <el-table-column
          v-if="index == 2"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.autoSend"
              :active-value="1"
              :inactive-value="2"
              @change=""
            >
            </el-switch>
          </template>
        </el-table-column>

        <el-table-column
          v-else
          :prop="i.data"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        />
      </template>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" @click="edit(scope.row)"
            >编辑</el-button
          >
          <el-button
            type="text"
            icon="el-icon-delete"
            style="color:#f56c6c;marginRight:10px"
            @click="del(scope.$index, scope.row)"
            >删除</el-button
          >
          <el-button type="primary" size="mini" @click="send(scope.row)"
            >发送</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="page">
      <el-pagination
        @size-change="sizeChange"
        @current-change="currentChange"
        :current-page.sync="page"
        :page-sizes="[20, 40, 80, 100]"
        :page-size="limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
    </div>

    <!-- 对话框 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="showDialog"
      width="40%"
      @close="showDialog = false"
    >
      <el-form
        v-model="form"
        ref="form"
        :rules="rules"
        label-width="120px"
        :inline="false"
        size="normal"
      >
        <el-form-item label="模板编号" prop="id">
          <el-input
            v-model="form.id"
            placeholder="请填写模板编号"
            style="width:220px"
          />
        </el-form-item>
        <el-form-item label="模板名称" prop="name">
          <el-input
            v-model="form.name"
            placeholder="请填写模板名称"
            style="width:220px"
          />
        </el-form-item>
        <el-form-item label="自动发送" prop="autoSend">
          <el-switch
            v-model="form.autoSend"
            :active-value="1"
            :inactive-value="2"
            @change=""
          />
        </el-form-item>
        <el-form-item label="模板内容" prop="content">
          <el-input
            v-model="form.content"
            type="textarea"
            placeholder="请填写可预约数量"
            style="width:420px"
          />
        </el-form-item>
        <el-form-item label="附带优惠券" prop="content">
          
          <el-button type="text" style="text-decoration: underline;" @click="showTicket=true">添加</el-button>
          <el-button type="text" style="text-decoration: underline;color:#ff6666" @click="">删除</el-button>
          
        </el-form-item>
      </el-form>
      <el-dialog
        title="选择优惠券"
        :visible.sync="showTicket"
        width="30%"
        append-to-body
        >
        <el-select v-model="ticket" placeholder="请选择优惠券" multiple clearable filterable @change="">
          <el-option label="优惠券1" value="1" />
          <el-option label="优惠券2" value="2" />
          <el-option label="优惠券3" value="3" />
        </el-select>
        
        <span slot="footer">
          <el-button type="primary" @click="">确定</el-button>
          <el-button @click="showTicket = false">取消</el-button>
        </span>
      </el-dialog>
      


      <span slot="footer">
        <el-button @click="showDialog = false">取消</el-button>
        <el-button type="primary" @click>确定</el-button>
      </span>
    </el-dialog>

    <!-- 发送用户列表 -->
    <el-dialog
      title="选择发送用户"
      :visible.sync="showUser"
      width="40%"
      @close="showUser = false"
    >
      <el-transfer
        v-model="sendUser"
        :data="userList"
        target-order="original"
        filterable
        :titles="['待选择','已选择']"
        @change=""
        :format="{ noChecked: '${total}', hasChecked: '${checked}/${total}' }"
      >
      </el-transfer>
      <span slot="footer">
        <el-button @click="showUser = false">取消</el-button>
        <el-button type="primary" @click="">提交</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "slider",
  data() {
    return {
      mId: "",
      mName: "",
      keyword: "",
      page: 1,
      limit: 10,
      total: 10,
      dialogTitle: "创建",
      form: {},
      showDialog: false,
      showUser: false,
      showTicket:false,
      ticket:[],
      sendUser: [],
      tableData: [
        {
          id: "1",
          createTime: "2021-02-21 12:22:31",
          model: "消息模板1",
          autoSend: 1
        },
        {
          id: "2",
          createTime: "2021-02-21 12:22:31",
          model: "消息模板2",
          autoSend: 2
        },
        {
          id: "3",
          createTime: "2021-02-21 12:22:31",
          model: "消息模板3",
          autoSend: 1
        }
      ],
      rules: {
        id: [{ required: true }],
        name: [{ required: true }],
        autoSend: [{ required: true }]
        // content: [{ required: true }]
      },

      userList: [
        { id: "111", label: "13322214311 用户a", key: "1" },
        { id: "222", label: "用户 222", key: "2" },
        { id: "333", label: "用户 333", key: "3" },
        { id: "444", label: "用户 444", key: "4" },
        { id: "555", label: "用户 555", key: "5" },
        { id: "666", label: "用户 666", key: "6" }
      ],

      columns: [
        { key: 0, label: `模板编号`, data: "id", visible: true, width: "80" },
        { key: 1, label: `模板名称`, data: "model", visible: true },
        {
          key: 2,
          label: `自动发送`,
          data: "autoSend",
          visible: true,
          width: "120"
        },
        { key: 3, label: `创建时间`, data: "createTime", visible: true }
      ],
      artQuery: {
        id: "1"
      }
    };
  },
  created() {},
  methods: {
    add() {
      this.showDialog = true;
    },
    edit(i) {
      this.showDialog = true;
    },
    del(i, d) {
      this.$confirm('确认删除所选数据？', "确认删除", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.tableData.splice(i, 1);
        })
        .catch(() => {});
    },
    send() {
      this.showUser = true;
    },
    sizeChange() {},
    beforeCoverUpload() {},
    currentChange() {}
  }
};
</script>
<style scoped>
.slideImg {
  width: 140px;
}
</style>
